<div id="vote">
	<div id="vote_group2">
		<ul>
			<li><a href="<?php echo $award_url.'vote#cat01';?>" target="_self">&nbsp;</a></li>
			<li><a href="<?php echo $award_url.'vote#cat02';?>" target="_self">&nbsp;</a></li>
			<li><a href="<?php echo $award_url.'vote#cat03';?>" target="_self">&nbsp;</a></li>
			<li><a href="<?php echo $award_url.'vote#cat04';?>" target="_self">&nbsp;</a></li>
			<li><a href="<?php echo $award_url.'vote#cat05';?>" target="_self">&nbsp;</a></li>
			<li><a href="<?php echo $award_url.'vote#cat06';?>" target="_self">&nbsp;</a></li>
			<li><a href="<?php echo $award_url.'vote#cat07';?>" target="_self">&nbsp;</a></li>
			<li><a href="<?php echo $award_url.'vote#cat08';?>" target="_self">&nbsp;</a></li>
			<li><a href="<?php echo $award_url.'vote#cat09';?>" target="_self">&nbsp;</a></li>
			<li><a href="<?php echo $award_url.'vote#cat10';?>" target="_self">&nbsp;</a></li>
			<li><a href="<?php echo $award_url.'vote#cat11';?>" target="_self">&nbsp;</a></li>
			<li><a href="<?php echo $award_url.'vote#cat12';?>" target="_self">&nbsp;</a></li>
		</ul>
		<div id="vote_group2_description">
			เตรียมตัวต้องมนต์สะกดกันไว้ให้ดีกับงานประกาศ<br /> 
			ผลรางวัลทางดนตรีแห่งปี “You2Play Awards 2014”<br />
			ที่จะร่ายเวทย์แห่งเสียงเพลง สีสัน และความมันส์<br />
			ขั้นสุด ให้คุณหฤหรรษ์กันสุดขั้ว 11 กุมภาพันธ์ นี้<br />
			ที่ รอยัล พารากอน ฮอลล์
		</div>
		<a href="<?php echo $award_url.'about';?>" target="_self" class="btnMore"></a>
	</div>
	<div id="vote_player">
		<div id="vdoPlayer">
			<?php if($this->agent->is_mobile()):?>
				<video id='my_video' controls preload='none'></video>
			<?php endif;?>
		</div>		
	</div>
	<!--Vote Block-->
	<?php for($cat=1;$cat<=12;$cat++):?>
		<?php
			//Calulate Total/Max Category
			$cat_total = $dataVote->{'cat'.sprintf("%02d",$cat).'_1'}+$dataVote->{'cat'.sprintf("%02d",$cat).'_2'}+$dataVote->{'cat'.sprintf("%02d",$cat).'_3'}+$dataVote->{'cat'.sprintf("%02d",$cat).'_4'}+$dataVote->{'cat'.sprintf("%02d",$cat).'_5'}+$dataVote->{'cat'.sprintf("%02d",$cat).'_6'};
			$cat_winner = max($dataVote->{'cat'.sprintf("%02d",$cat).'_1'},$dataVote->{'cat'.sprintf("%02d",$cat).'_2'},$dataVote->{'cat'.sprintf("%02d",$cat).'_3'},$dataVote->{'cat'.sprintf("%02d",$cat).'_4'},$dataVote->{'cat'.sprintf("%02d",$cat).'_5'},$dataVote->{'cat'.sprintf("%02d",$cat).'_6'});
		?>	
		<a name="cat<?php echo sprintf("%02d",$cat);?>"></a>
		<div class="voteBlock <?php echo ($cat == 1 ? 'first':'');?>">
			<div class="stamp">
				<span class="categoryStamp stamp<?php echo sprintf("%02d",$cat);?>"></span>
			</div>
			<div class="categoryTitle"><?php echo $dataCategory[''.sprintf("%02d",$cat).''];?></div>
			<ul>
				<?php for($indexAt=1;$indexAt<=6;$indexAt++):?>
				<li <?php echo 'style="background-color:'.$dataCategoryColor[$cat].';"';?>>
					<a href="<?php echo $award_url.$asset_award_artis_path.sprintf("%02d",$cat)."/".sprintf("%02d",$indexAt);?>" target="_blank" class="voteSeeeArtist">
						<div class="image">
							<?php echo image_asset($asset_award_upload_path.$asset_award_artis_path.''.sprintf("%02d",$cat).''.'/'.sprintf('%02d',$indexAt).'/vote_thumb.jpg','',array('width' => 142,'height' => 142));?>	
						</div>
						<h3><?php echo ${'dataXML'.sprintf("%02d",$cat).sprintf("%02d",$indexAt)}->vote_artist_name;?></h3>
						<p><?php echo ${'dataXML'.sprintf("%02d",$cat).sprintf("%02d",$indexAt)}->vote_description;?></p>
					</a>
					<?php if($this->expireActivity < time()):?>
						<?php if($this->showWinner < time()):?>
							<?php if($cat_winner == $dataVote->{'cat'.sprintf("%02d",$cat).'_'.$indexAt}):?>
								<a class="buttonWinner"></a>
							<?php endif;?>						
						<?php else:?>
							<a class="buttonClosed">ปิดโหวต</a>
						<?php endif;?>
					<?php else:?>
						<a <?php echo (@${'cat'.sprintf("%02d",$cat)} == $indexAt ? 'class="buttonVoted"':'class="buttonVote"');?> <?php echo (isset(${'cat'.sprintf("%02d",$cat)}) && @${'cat'.sprintf("%02d",$cat)} != $indexAt ? 'style="visibility:hidden;"':'');?> href="javascript:void(0);" onclick="javascript:voteCat(this,'<?php echo sprintf("%02d",$cat);?>','<?php echo $indexAt;?>');"></a>
					<?php endif;?>
					<?php if($this->expireShowPercent > time() || $this->showWinner < time()):?>
					<div class="voteScore"><?php echo ($cat_total == 0 ? '0.00':sprintf("%.2f",($dataVote->{'cat'.sprintf("%02d",$cat).'_'.$indexAt}*100)/$cat_total));?>%</div>
					<?php endif;?>
				</li>
				<?php endfor;?>
			</ul>
		</div>
	<?php endfor;?>
</div>
<script type="text/javascript" language="javascript">
(function($) {
/*whatever jQuery stuff*/
	$(function(){
		var is_mobile = '<?php echo $this->agent->is_mobile();?>';
		//Set Video Source
		var url = "<?php echo image_asset_url($asset_award_upload_path.'home.mp4');?>";		
		if(is_mobile){
			$('#my_video').append("<source id='mp4' src='"+url+"' type='video/mp4'>");
			$('#my_video').attr('src',""+url+"");
			$('#my_video').attr('width',530);
			$('#my_video').attr('height',320);
			// videoplaza sdk, 4 sec time-out, callback function
			loadScript("<?php echo js_asset_url('media/html5-sdk-1.0.12.15.1-ea.min.js');?>",4000,initVideoplaza);
			// *** START - videoplaza plugin config ***
			vpConfig = {
				vphost : 'http://th-pmdplus.videoplaza.tv',
				category : 'award',
				tags : ['standard'],
				flags: [],
				playbackPosition: [] // mid-roll cue points, if any.
			}
			// *** END - videoplaza plugin config ***
			//Auto Play && Loop
			$('#my_video').attr('autoplay','autoplay');	
		} else {	
			jwplayer("vdoPlayer").setup({
				autostart: true,
		      	flashplayer: "<?php echo js_asset_url('media/player.swf');?>",
		      	width: 530,
		      	height: 320,
				file: ""+url+"",
		      	plugins: "<?php echo js_asset_url('media/vp_plugin.swf');?>",
		      	vpdomain: "http://th-pmdplus.videoplaza.tv",
		      	vpshares: "award",
		      	vptags: "",
               	provider: "http",
        		startparam: "starttime"					
			});
		}				
	});	
})(jQuery);
/*Vote Category*/
function voteCat(e,cat,at)
{
	var expireShowPercent = '<?php echo $this->expireShowPercent;?>';
	var todayTime = '<?php echo time();?>';
	$.ajax({
		url:web_path+'award/ajax_vote?t='+new Date().getTime(),
		type:'post',
		data:({
			cat:cat,
			at:at
		}),
		dataType:'json'
	}).done(function(data){
		if(data.error == 1){
			alert('กรุณา Login ด้วย Facebook ก่อนทำการโหวต.');
			//$(document).scrollTop(0);
			$('html, body').animate({
    			scrollTop: 0
 			}, 1000);
		} else if(data.error == 2){
			alert('คุณมีสิทธิ์ในการโหวตได้ 2 ครั้ง ในหนึ่งชั่วโมง\nคุณสามารถกลับมาโหวตได้อีกครั้งภายในครึ่งชั่วโมง');
		} else if(data.error == 3){
			alert('ขออภัยค่ะ ปิดกิจกรรมการโหวตเรียบร้อยแล้ว');			
		} else {
			if(expireShowPercent > todayTime){
				$(e).closest('.voteBlock').find('.voteScore').each(function(i,key){
					$(this).html(data[i]+'%');
				});				
			}
			
			//change image to voted
			$(e).attr('class','buttonVoted');
			$(e).closest('.voteBlock').find('.buttonVote').css({visibility:'hidden'});
		}
	});
}
</script>	